import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils


@allure.feature('TestCase_45: 当前阶段的保养计划, 显示"去保养"按钮, 其他阶段, 不显示"去保养"按钮		')
@allure.issue(
    'https://www.tapd.cn/54441127/sparrow/tcase/view/1154441127001066086?url_cache_key=5b07a59231afaf505fb7dc2f4205dfae')
class TestCaseService45:
    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        # 桌面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()
        # 车服务
        self.service_index_page = CommonPage(self.driver).get_service_index_page()
        self.service_city_page = CommonPage(self.driver).get_service_city_page()
        self.service_customer_hotline_page = CommonPage(self.driver).get_service_customer_hotline_page()
        self.service_driving_score_page = CommonPage(self.driver).get_service_driving_score_page()
        self.service_health_house_keeper_page = CommonPage(self.driver).get_service_health_house_keeper_page()
        self.service_maintenance_plan_page = CommonPage(self.driver).get_service_maintenance_page()
        self.service_my_reservation_page = CommonPage(self.driver).get_service_my_reservation_page()
        self.service_new_operating_page = CommonPage(self.driver).get_service_new_operating_page()
        self.service_reservation_page = CommonPage(self.driver).get_service_reservation_page()
        self.service_store_select_page = CommonPage(self.driver).get_service_store_select_page()
        self.service_time_page = CommonPage(self.driver).get_service_time_page()
        self.service_phone_page = CommonPage(self.driver).get_service_phone_page()
        #     个人中心
        self.personal_index_page = CommonPage(self.driver).get_personal_index_page()

    def teardown_class(self):
        XiaoMaUtils.close_app('service')
        # XiaoMaUtils.clear_data('personal')
        self.driver.quit()

    @allure.story('step1:点击应用页,进入车辆管家')
    @pytest.mark.run(order=451)
    def test_service_45_1_click_list(self):
        try:
            self.launcher_index_page.click_app_list()
            self.launcher_app_list_page.click_appname(TestCase.SERVICE)
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step2: 当前阶段的保养计划, 显示去保养按钮, 其他阶段, 不显示去保养按钮")
    @pytest.mark.run(order=452)
    def test_service_45_2_click_service(self):
        try:
            self.service_index_page.is_display_service_index()
            self.service_index_page.click_list_category("养车计划")
            self.service_maintenance_plan_page.is_display_service_maintenance()
            text1 = self.service_maintenance_plan_page.get_ele_text(self.service_maintenance_plan_page.get_mileage_go_maintenance())
            text2 = self.service_maintenance_plan_page.get_ele_text(self.service_maintenance_plan_page.get_mileage_go_maintenance())
            if text1:
                if text2 == None:
                    print('按钮显示正常')
                else:
                    print('按钮显示异常')
            else:
                print('当前保养没有位于首页请联系开发')
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == 'main__':
    # pass
    pytest.main("-s testcase_service_45.py")
